<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2024/8/9
  Time: 16:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
    <form id="formId" method="post">
        用户名<input type="text" name="name"><br>
        密码<input type="password" name="password"><br>
        验证码<input type="text" name="code"><img id="verifyCodeId"  onclick="refresh()" src="/verifyCode"><br>
        <input type="button" onclick="submitForm()" value="提交">
    </form>
    <script src="/static/js/jquery-2.1.4.js"></script>
    <script src="/static/js/mylayer.js"></script>
    <script src="/static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script>
        //刷新验证码
        function refresh(){
            $('#verifyCodeId').attr('src','/verifyCode?'+Math.random())
        }
        //提交数据到loginservlet，判断验证码是否正确，可以返回个成功的msg
        function submitForm() {
            $.post(
                '/admin?method=login',
                $('#formId').serialize(),
                function (result) {
                    console.log(result);
                    if (result.code == 0) {
                        mylayer.okUrl(result.msg, '/');
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
